package icasue.net.protocol.carfun.common;

/**
 * @Author: Qiao Hang
 * @CreateDate: 2021/3/19 下午3:54
 * @UpdateDate:
 * @Description: 服务端响应的公共格式
 */
public class CommandResponse<T> {
    private Integer code;
    private String message;
    private T data;

    public CommandResponse(Integer code,String message){
        this.code = code;
        this.message = message;
    }

    public CommandResponse(BizCode bizCode){
        this.code = bizCode.code;
        this.message = bizCode.message;
    }

    public static <T> CommandResponse success(T data){
        CommandResponse success = new CommandResponse(BizCode.SUCCESS);
        success.data = data;
        return success;
    }

    public static <T> CommandResponse error(){
        return new CommandResponse(BizCode.ERROR);
    }

    public static <T> CommandResponse error(BizCode bizState){
        return new CommandResponse(bizState);
    }

    public static <T> CommandResponse error(Integer code,String message){
        return new CommandResponse(code,message);
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
